package com.etymgiko.lyricscollectionseam.session;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.jboss.seam.annotations.Name;

import com.etymgiko.lyricscollectionseam.entity.Song;

/**
 * @author Ivan Holub
 */
@Stateless
@Name("songManager")
public class SongManagerImpl implements SongManager {

	@PersistenceContext
	private EntityManager em;

	public Song findSong(Long artistId, String title) {
		Query query = em
				.createQuery("select song from Song song where song.artist.id = ? and song.title = ?");
		query.setParameter(1, artistId);
		query.setParameter(2, title);
		Song retValue = null;
		List<Song> list = query.getResultList();
		if (list.size() > 0) {
			retValue = list.get(0);
		}
		return retValue;

	}

}
